package com.tengju.bff.interfaces.manage.crm.staff.department;

import com.tengju.bff.interfaces.shared.ApiResponse;
import com.tengju.bff.interfaces.shared.servlet.ManageEntrance;
import com.tengju.user.domain.model.department.DepartmentTree;
import com.tengju.user.domain.model.user.StaffSimpleInfo;
import com.tengju.user.domain.service.DepartmentExternalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: 李大仙
 * @Date: 2021/4/20 3:43 下午
 */
@Validated
@RestController
@Api(tags = "运营人员部门信息")
@RequestMapping(value = "manage/crm/staff/department")
@Slf4j
@ManageEntrance
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class DepartmentController {

    private final DepartmentExternalService departmentExternalService;

    @ApiOperation(value = "获取部门信息树", notes = "获取部门信息树")
    @RequestMapping(value = "/tree", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<List<DepartmentTree>> list() {
        List<DepartmentTree> departmentTree = departmentExternalService.getDepartmentTree();
        return ApiResponse.newSuccess(departmentTree);
    }

    @ApiOperation(value = "获取部门及以下部门的人员信息", notes = "获取部门及以下部门的人员信息")
    @RequestMapping(value = "/staff/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<List<StaffSimpleInfo>> staffList(Long departmentId) {
        List<StaffSimpleInfo> list = departmentExternalService.getStaffSimpleInfosByDepartmentId(departmentId);
        return ApiResponse.newSuccess(list);
    }

    @ApiOperation(value = "通过员工姓名获取部门及以下部门的人员信息", notes = "通过员工姓名获取部门及以下部门的人员信息")
    @RequestMapping(value = "/staff/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ApiResponse<List<StaffSimpleInfo>> staffList(Long departmentId, String name) {
        List<StaffSimpleInfo> list = departmentExternalService.getStaffSimpleInfosByDepartmentIdAndName(departmentId, name);
        return ApiResponse.newSuccess(list);
    }
}
